# -*- coding: utf-8 -*-
"""
@Time    : 2024/7/17 10:42 
@Author  : ZhangShenao 
@File    : 2.使用Playwright实现网页自动化测试.py
@Desc    : 使用Playwright实现网页自动化测试
"""
from playwright.sync_api import sync_playwright


def run():
    """使用Playwright执行自动化测试"""

    # 使用Playwright上下文管理器
    with sync_playwright() as p:
        # 使用chromium,即Chrome浏览器工具
        browser = p.chromium.launch()

        # 创建一个新的页面
        page = browser.new_page()

        # 跳转到指定的URL
        page.goto('https://www.imooc.com/')

        # 获取并打印页面标题
        title = page.title()
        print(f'title is {title}')

        # 关闭浏览器
        browser.close()


if __name__ == '__main__':
    # 执行自动化测试
    run()
